package com.tc168.cp306.b06.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.tc168.cp306.b06.MyApplication;
import com.tc168.cp306.b06.R;
import com.tc168.cp306.b06.Utils.ToastUtil;
import com.tc168.cp306.b06.activity.TIJIActivity;
import com.tc168.cp306.b06.bean.UserAnswerbean;
import com.tc168.cp306.b06.gen.UserAnswerbeanDao;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;


/**
 * A simple {@link Fragment} subclass.
 * <p>
 * 查看记录
 */
public class JIluFragment extends Fragment {


    @BindView(R.id.jilvone)
    TextView jilvone;
    @BindView(R.id.jilvtwo)
    TextView jilvtwo;
    @BindView(R.id.jilvthree)
    TextView jilvthree;
    @BindView(R.id.jilvfour)
    TextView jilvfour;
    @BindView(R.id.jilvfive)
    TextView jilvfive;
    @BindView(R.id.jilv_cuo)
    Button jilvCuo;
    @BindView(R.id.jilv_qing)
    Button jilvQing;
    @BindView(R.id.jilv_all)
    Button jilvAll;
    Unbinder unbinder;
    private List<UserAnswerbean> listcuo;
    private List<UserAnswerbean> listzhengque;

    public JIluFragment() {
        // Required empty public constructor
    }

    private UserAnswerbeanDao topticbeanDao;

    private int num;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_jilu, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        topticbeanDao = MyApplication.getmDaoSessiontwo().getUserAnswerbeanDao();

        listcuo = topticbeanDao.queryBuilder().where(UserAnswerbeanDao.Properties.Istrue.eq(false)).list();

        listzhengque = topticbeanDao.queryBuilder().where(UserAnswerbeanDao.Properties.Istrue.eq(true)).list();
//今日答题情况： 0题
        num = listcuo.size() + listzhengque.size();

        jilvone.setText("今日答题情况： " + num + "题");

        jilvtwo.setText("今日答题情况： " + listcuo.size() + "题");
        jilvthree.setText("今日答题情况： " + num + "题");
        jilvfour.setText("今日答题情况： " + listzhengque.size() + "题");
        jilvfive.setText("今日答题情况： " + listcuo.size() + "题");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.jilv_cuo, R.id.jilv_qing, R.id.jilv_all})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.jilv_cuo:

                startActivity(new Intent(getActivity(),TIJIActivity.class));
                break;
            case R.id.jilv_qing:
                topticbeanDao.detachAll();
                ToastUtil.showLong(getActivity(),"已经清空完毕");
                break;
            case R.id.jilv_all:
                ToastUtil.showLong(getActivity(),"已经清空完毕");

                break;
        }
    }
}
